package com.bsh.controller;

import com.bsh.entity.*;
import com.bsh.entity.Bo.TbClass;
import com.bsh.entity.Bo.TbScore;
import com.bsh.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/students")
@Api(tags = "学生信息管理")
public class StudentController {

    @Resource
    private StudentService studentService;

    /**
     *输出所有学生清单，包含如下列：
     * 学生编号、班级名称、年级、班主任姓名、学生姓名、学生性别、出生日期
     * @param pageIndex 页数
     * @param pageSize 条数
     * @return 结果
     */
    @GetMapping("/getStudentsList")
    @ApiOperation("输出所有学生清单")
    public Result getStudentsList(
            @RequestParam(defaultValue = "1", required = false) Integer pageIndex,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize) {

        return Result.page(studentService.getStudentsList(pageIndex, pageSize));
    }

    /**
     *输出【年龄大于等于17岁】且【性别为女】且【班主任为战豆豆】的学生清单，包含如下列：
     *学生编号、班级名称、年级、班主任姓名、学生姓名、学生性别、出生日期
     * @param pageIndex 页数
     * @param pageSize 条数
     * @return 结果
     */
    @GetMapping("/getFilteredStudents")
    @ApiOperation("输出特定条件的学生清单")
    public Result getFilteredStudents(
            @RequestParam(defaultValue = "1", required = false) @ApiParam("页数") Integer pageIndex,
            @RequestParam(defaultValue = "10", required = false) @ApiParam("条数") Integer pageSize) {
        return Result.page(studentService.getFilteredStudents(pageIndex,pageSize));
    }


    /**
     *输出各班语文课成绩汇总结果，包含如下列：
     * 班级编号、班级名称、年级、班主任姓名、语文最低分、语文最高分、语文平均分
     * @param pageIndex 页数
     * @param pageSize 条数
     * @return 结果
     */
    @GetMapping("/getChineseScoreSummary")
    @ApiOperation("查询各班级语文成绩")
    public Result getChineseScoreSummary(@RequestParam(defaultValue = "1", required = false) @ApiParam("页数") Integer pageIndex,
                                         @RequestParam(defaultValue = "10", required = false) @ApiParam("条数") Integer pageSize) {
        return Result.page(studentService.getChineseScoreSummary(pageIndex,pageSize));
    }


    /**
     *输输出【班主任为林婉儿】的班里学生的总分清单，包含如下列：
     * 班级名称、年级、班主任姓名、学生编号、学生姓名、总分
     * @param teacherName 班主任姓名
     * @param pageIndex 页数
     * @param pageSize 条数
     * @return 结果
     */
    @GetMapping("{teacherName}/getStudentTotalScoreByTeacher")
    @ApiOperation("获取某老师班里学生的总分清单")
    public Result getStudentTotalScoreByTeacher(
            @PathVariable("teacherName") String teacherName,
            @RequestParam(defaultValue = "1", required = false)  @ApiParam("页数")Integer pageIndex,
            @RequestParam(defaultValue = "10", required = false)  @ApiParam("条数")Integer pageSize) {
        return Result.page(studentService.getStudentTotalScoreByTeacher(teacherName, pageIndex, pageSize));
    }


    /**
     *输出所有学生的成绩汇总表，包含如下列：
     * 学生编号、学生姓名、学生性别、出生日期、语文分数、数学分数、英语分数、物理分数、化学分数、生物分数、总分
     * @param pageIndex 页数
     * @param pageSize 条数
     * @return 结果
     */
    @GetMapping("getStudentScoreSummary")
    @ApiOperation("输出所有学生的成绩汇总表")
    public Result getStudentScoreSummary(
            @RequestParam(defaultValue = "1", required = false)  @ApiParam("页数")Integer pageIndex,
            @RequestParam(defaultValue = "10", required = false)  @ApiParam("条数")Integer pageSize) {
        return Result.page(studentService.getStudentScoreSummary(pageIndex,pageSize));
    }

    @PostMapping("/insertClass")
    @ApiOperation("新增班级")
    public Result insertClass(@RequestBody TbClass tbClass){
        studentService.insertClass(tbClass);
        return Result.success();
    }
    @PostMapping("/insertScore")
    @ApiOperation("新增成绩单")
    public Result insertScore(@RequestBody TbScore tbScore){
        studentService.insertScore(tbScore);
        return Result.success();
    }

    @DeleteMapping("deleteClassById/{id}")
    @ApiOperation("删除班级")
    public Result deleteClassById(@PathVariable("id") Integer id){

        studentService.deleteClassById(id);
        return Result.success();
    }





}
